package com.baizhi.service.impl;

import com.baizhi.entity.Admin;
import com.baizhi.entity.Role;
import com.baizhi.mapper.RoleMapper;
import com.baizhi.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author longyang
 * @since 2022-01-13
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public List<Role> selectAllRole() {
        return roleMapper.selectList(null);
    }

    @Override
    public Integer addRole(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public Integer deleteRole(Integer roleId) {
        return roleMapper.deleteById(roleId);
    }

    @Override
    public Role selectRoleByroleId(Integer roleId) {
        //条件构造器：用于构建sql条件
        QueryWrapper<Role> queryWrapper = new QueryWrapper<Role>();
        queryWrapper.eq("role_id",roleId);
        return roleMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer updateRole(Role role) {
        return roleMapper.updateById(role);
    }
}
